package com.question.business.dict.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.question.business.dict.entity.DictType;
import com.question.business.dict.model.ao.DictTypePageAO;
import com.question.business.dict.model.dto.DictCacheDTO;
import com.question.business.dict.model.vo.DictTypeVO;
import com.question.common.annotation.DataConvert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 字典类型Mapper接口
 *
 * @author star
 * @since 2023-09-07
 */
@Mapper
public interface DictTypeMapper extends BaseMapper<DictType> {
    /**
     * 字典类型分页查询
     *
     * @param page 分页参数
     * @param ao   请求参数
     * @return Page<DictTypeVO> 响应参数
     */
    @DataConvert
    Page<DictTypeVO> queryDictTypePage(Page<DictTypeVO> page, @Param("ao") DictTypePageAO ao);

    /**
     * 查询字典类型数量
     *
     * @param dictType 字典类型
     * @return int
     */
    @Select("SELECT COUNT(*) FROM t_dict_type WHERE is_deleted = 0 AND dict_type = #{dictType}")
    int queryByType(String dictType);

    /**
     * 查询用户缓存
     *
     * @return List<DictCacheDTO>
     */
    @Select("SELECT t.dict_type,d.id,d.dict_code,d.dict_desc FROM t_dict_type t LEFT JOIN t_dict d ON d.type_id = t.id WHERE t.is_deleted = 0 AND t.enabled = 1")
    List<DictCacheDTO> queryDictCache();
}